package it.lefo.dateReminder.service;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;

public class ReminderService extends Service {

	private static ReminderThread thread = null;

	@Override
	public IBinder onBind(Intent intent) {
		return null;

	}

	private ReminderThread getReminderThread() {
		if (thread == null) {
			thread = new ReminderThread(this);
		}
		return thread;
	}

	@Override
	public void onCreate() {
		super.onCreate();
		Log.i(ReminderService.class.getSimpleName(), "onCreate Start");

		Log.i(ReminderService.class.getSimpleName(), "onCreate End");
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
		Log.i(ReminderService.class.getSimpleName(), "onDestroy Start");

		Toast.makeText(this, "Service Destroyed", Toast.LENGTH_LONG).show();
		getReminderThread().stop();

		Log.i(ReminderService.class.getSimpleName(), "onDestroy End");

	}

	@Override
	public void onStart(Intent intent, int startId) {

		super.onStart(intent, startId);
		Log.i(ReminderService.class.getSimpleName(), "onStart Start");

		getReminderThread().run();
		Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show();

		Log.i(ReminderService.class.getSimpleName(), "onStart End");
	}

}
